﻿using ProjectFootball.MVC.Foundation.ResourceLibrary;
using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Security.Principal;

namespace ProjectFootball.MVC.Foundation
{
    public abstract class BaseApprovableEntity
    {
        #region Constructors
        public BaseApprovableEntity()
        {
        }

        public BaseApprovableEntity(IPrincipal user, CreateType createType, Guid approvalGuid)
        {
            Pk = Guid.NewGuid();
            ApprovalGuid = createType == CreateType.Unapproved ? approvalGuid : Guid.NewGuid();
            IsPublic = createType != CreateType.Private;
            IsApproved = createType != CreateType.Unapproved;
            IsMarkedForDeletion = false;
            OwnerUserId = user.GetUserId();
            AuditUserId = user.GetUserId();
            AuditTimestamp = DateTime.Now;
        }
        #endregion

        [Key]
        [Column(Order=0)]
        public Guid Pk { get; set; }

        public Guid ApprovalGuid { get; set; }

        public bool IsPublic { get; set; }

        public bool IsApproved { get; set; }

        public bool IsMarkedForDeletion { get; set; }

        [ForeignKey("OwnerUser")]
        public int OwnerUserId { get; set; }

        [ForeignKey("AuditUser")]
        public int AuditUserId { get; set; }

        public DateTime AuditTimestamp { get; set; }

        [ForeignKey("OwnerUserId")]
        public virtual UserProfile OwnerUser { get; set; }

        [ForeignKey("AuditUserId")]
        public virtual UserProfile AuditUser { get; set; }
    }
}